package main.java.com.negromotad.genetics;

import org.jgap.FitnessFunction;
import org.jgap.IChromosome;

public class TMFitnessFunction extends FitnessFunction {

	/**
	 * 
	 */
	private Double[][] entry;
	private int rows;
	private int cols;

	public TMFitnessFunction(Double[][] theEntry, int rows, int col) {
		entry = theEntry;
		this.rows = rows;
		this.cols = col;
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 2830747316578204303L;

	@Override
	protected double evaluate(final IChromosome arg0) {
		float partial = 0;
		float total = 0;
		for (int i = 0; i < rows; i++) {
			for (int j = 0; j < cols; j++) {
				partial += entry[i][j] * (Integer) arg0.getGene(j).getAllele()
						/ 100;
			}
			total += partial;
			partial = 0;
		}
		return total;
	}

}
